<?php
declare (strict_types=1);

namespace app\api\controller\v1;

use app\common\model\Course;
use app\common\model\Grade;
use app\common\model\Unit as UnitModel;

class ErrorLog extends BaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        return sucessMsg(200, '获取成功', [
            'list' => $this->getList(),     //  获取错题信息
        ]);
    }

    /*
     * 获取错误信息
     * */
    public function getList()
    {
        $type = input('type/d', 1);
        $page = input('page/d',1);
        $pageSize = input('pageSize/d',15);
        $model = new \app\common\model\Error();
        $where['type'] = $type;
        $list = $model->where($where)->order(['id'=>'desc'])->page($page,$pageSize)->select()->toArray();
        foreach ($list as $k=>$v){
            $grade = Grade::find($v['grade_id']);   //  年级id
            $unit = UnitModel::find($v['unit_id']);     //  单元id
            $course = Course::find($v['course_id']);    //  分类
            $list[$k]['grade_name'] = $grade->title;
            $list[$k]['unit_name'] = $unit->title;
            $list[$k]['course_name'] = $course->title;
        }
        return $list;
    }
}
